function [ f ] = plotBandedResponsivenessFeatureData( data )
%PLOTBANDED Plot the imagedata of a banded frequency analysis
%   Returns a handle to the figure
%   Input argument (data) is a structure:
%           data.bands{x}.foi
%           data.bands{x}.description
%           data.bands{x}.normalizedMeanDiff
%           data.bands{x}.stimulusVar
%           data.bands{x}.restVar
%           data.electrodeLabels
%           data.setDescription
    p = zeros(length(data.bands), length(data.electrodeLabels));
    bandLabels = cell(1,9);
    for i = 1:length(data.bands)
        p(i,:) = mean(data.bands{i}.normalizedMeanDiff,1);
        bandLabels{i} = data.bands{i}.description;
    end
    pMin = min(p,[],1);
    pMax = max(p,[],1);
    
    feat1 = pMax - pMin;
    feat2 = max(abs([pMax;pMin]));
    fig = barh ([feat1;feat2]');



end


function createfigure(ymatrix1)
% f = figure('PaperSize',[20.98 29.68],'Name','Feature data',...
%     'Color',[1 1 1]);
f = figure('PaperOrientation','landscape','Colormap', colormap);

% Create axes
axes1 = axes('Parent',figure1,...
    'YTickLabel',{'Elec1','Elec2','Elec3','Elec4','50','60','70','80','90'},...
    'YTick',[1 2 3 4 50 60 70 80 90],...
    'XGrid','on',...
    'FontSize',5);
% Uncomment the following line to preserve the Y-limits of the axes
% ylim(axes1,[0.5 96.5]);
box(axes1,'on');
hold(axes1,'all');

% Create multiple lines using matrix input to bar
bar1 = bar(ymatrix1,'ShowBaseLine','off','Horizontal','on','BarWidth',0.6);
set(bar1(1),'DisplayName','Blue');
set(bar1(2),'DisplayName','Red');

% Create xlabel
xlabel('Value');

% Create ylabel
ylabel('Electrode');






% 
% 
% colormap = [0 0 0.5625;0 0 0.625;0 0 0.6875;0 0 0.75;0 0 0.8125;0 0 0.875;0 0 0.9375;0 0 1; ...
%     0 0.0625 1;0 0.125 1;0 0.1875 1;0 0.25 1;0 0.3125 1;0 0.375 1;0 0.4375 1;0 0.5 1;0 0.5625 1;0 0.625 1;0 0.6875 1;0 0.75 1;0 0.8125 1;0 0.875 1;0 0.9375 1;0 1 1; ...
%     0.1429 1 1;0.2857 1 1;0.4286 1 1;0.5714 1 1;0.7143 1 1;0.8571 1 1;1 1 1; ...
%     1 1 0.8889;1 1 0.7778;1 1 0.6667;1 1 0.5556;1 1 0.4444;1 1 0.3333;1 1 0.2222;1 1 0.1111;1 1 0; ...
%     1 0.9375 0;1 0.875 0;1 0.8125 0;1 0.75 0;1 0.6875 0;1 0.625 0;1 0.5625 0;1 0.5 0;1 0.4375 0;1 0.375 0;1 0.3125 0;1 0.25 0;1 0.1875 0;1 0.125 0;1 0.0625 0;1 0 0; ...
%     0.9375 0 0;0.875 0 0;0.8125 0 0;0.75 0 0;0.6875 0 0;0.625 0 0;0.5625 0 0;0.5 0 0];
% 
% 
% 
% 
% 
% 
% 
% % plotSpacing = 0.007;
% % plotHeight = ((0.8 + plotSpacing) / length(data.bands)) - plotSpacing;
% % for b = 1:length(data.bands)
% %     bottom = 0.1 + (b-1)*(plotHeight+plotSpacing);
% %     ax = axes('Parent', f, ...
% %         'FontSize', 5, ...
% %         'Color', 'none', ...
% %         'CLim', [-1 1], ...
% %         'Box', 'on', ...
% %         'XTick', [], ...
% %         'Position', [0.03 bottom 0.9 plotHeight]);
% %     
% %     xlim(ax, [0.5 numberOfChannels+0.5]);
% %     step = (data.bands{b}.foi(2)-data.bands{b}.foi(1))/2;
% %     ylim(ax, [min(data.bands{b}.foi)-step max(data.bands{b}.foi)+step]);
% % 
% %     hold(ax,'all');
% %     image(1:numberOfChannels, data.bands{b}.foi, data.bands{b}.normalizedMeanDiff, 'Parent', ax, 'CDataMapping', 'scaled');
% % end
% % 
% p = zeros(length(data.bands)+1, length(data.electrodeLabels)+1);
% bandLabels = cell(1,9);
% for i = 1:length(data.bands)
%     p(i,1:length(data.electrodeLabels)) = mean(data.bands{i}.normalizedMeanDiff,1);
%     bandLabels{i} = data.bands{i}.description;
% end
% 
% ax0 = axes('Parent', f,...
%     'Position',[0.03 0.1 0.9 0.8],... % left, bottom, width, height
%     'Layer', 'top', ...
%     'Visible', 'on', ...
%     'Color', 'none', ...
%     'CLim', [-1 1], ...
%     'YTickLabel', data.electrodeLabels, ...
%     'YTick', 1.5:numberOfChannels+0.5, ...
%     'XTickLabel', bandLabels, ...
%     'XTick', 1.5:length(bandLabels)+0.5, ...
%     'FontSize', 5);
% set(get(ax0,'XLabel'),'String','Band');
% set(get(ax0,'YLabel'),'String','Electrode');
% title(ax0, data.setDescription, 'FontSize',12);
% hold on;
% pcolor(ax0, p');
% 
% colorbar('peer', ax0, ...
%     'FontSize', 5, ...
%     'CLim', [-1 1], ...
%     'Position', [0.95 0.1 0.015 0.8], ...
%     'YAxisLocation', 'left', ...
%     'YTick', -0.8:0.2:0.8, ...
%     'YTickLabel', {'-80%', '-60%', '-40%', '-20%', '0%', '20%', '40%', '60%', '80%'}, ...
%     'TickLength', [0 0]);
% 
% % New axes for vertical electrode labels
% % ax1 = axes('Parent', f,...
% %     'Position',[0.03 0.07 0.9 0.8],... % left, bottom, width, height
% %     'Layer', 'top', ...
% %     'Visible', 'off', ...
% %     'Color', 'none', ...
% %     'XLim', [0.5 numberOfChannels+0.5], ...
% %     'XTickLabel', data.electrodeLabels, ...
% %     'XTick', 1:length(data.electrodeLabels), ...
% %     'YTick', [], ...
% %     'Box', 'on', ...
% %     'XGrid','on',...
% %     'FontSize', 5);
% % set(get(ax1,'XLabel'),'String',[]);
% % set(get(ax1,'YLabel'),'String',[]);
% % xticklabel_rotate([], 90, data.electrodeLabels); % fucks up the positioning :(
% 
% end




